package cn.main.service.impl;

import cn.main.dao.DomainDao;
import cn.main.entity.sys.SysColumn;
import cn.main.entity.sys.SysFunction;
import cn.main.entity.sys.User;
import cn.main.service.SysService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;

/**
 * Author: chengwei
 * Date:   2016/5/17
 * Time:   9:31
 */
@Service
public class SysServiceImpl implements SysService{

    @Resource
    private DomainDao dao;

    private Map<String,Object> map = new HashMap<>();
    @Override
    public Map<String, Object> getFunction(User user,String columnId) {
        Map<String,Object> map = new HashMap<>();
        dao.setCacheQueries(true);

        SysColumn column =dao.getDomain(columnId,SysColumn.class);
        Set<SysFunction> functions = null;
        if (column != null) {
            functions = column.getFunctions();
            for (SysFunction function : functions) {
                function.setRoles(null);
                function.setColumn(null);
            }
        }
//        List<SysFunction> functions = dao.getDomains(SysFunction.class,"column_id = ?",columnId);
        map.put("function", functions);
        return map;
    }

    @Override
    public Map<String, Object> getCarousel(User user, String function_id) {
        
        return null;
    }

    @Override
//    @Transactional(isolation = Isolation.REPEATABLE_READ)
    public Map<String, Object> getFunction(String functionId) {
        SysFunction function = dao.getDomain(functionId,SysFunction.class);
        Map<String,Object> map = new HashMap<>();
//        SysFunction f = new SysFunction();
//        f.setName("单元");
//        f.setFunctionId(UUID.randomUUID().toString().replace("-",""));
//        f.setColumnId(function.getColumnId());
//        dao.saveDomain(f);
        map.put("function_id",function.getFunctionId());
        map.put("name",function.getName());
//        map.put("column_id",functio);
        return map;
    }
}
